import React, { Component } from "react";
import Child from "./Child";
import { connect } from "react-redux";

import { addAction } from "./store/actionCreator";

const mapStateToProps = (state) => {
  return {
    count: state.count,
  };
};

const mapDispatchToProps = (dispatch) => {
  return {
    add() {
      // dispatch({ type: "add" });
      dispatch(addAction());
    },
  };
};

class App extends Component {
  state = {};

  handleClick = () => {
    this.props.add();
  };

  render() {
    return (
      <>
        <h2>redux异步操作</h2>
        <p>
          count: {this.props.count} -{" "}
          <button onClick={this.handleClick}>btn</button>
        </p>
        <Child />
      </>
    );
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(App);
